<?php
 function sqlresult2xml($result) {
   $xml='';
   if($result===true) {//not a query, was a command
     $xml.=sprintf('<result rows_affected="%s"/>',mysql_affected_rows());
     return $xml;
   } 
   if($result!=false) {//if not true and not false, then their must be some rows
     $xml.=sprintf('<result rows="%s" cols="%s">',
       $count=mysql_num_rows($result),
       mysql_num_fields($result)
     );
     for($i=0;$i<$count;$i++) {
       $row=mysql_fetch_assoc($result);
       $xml.=sprintf('<row rownum="%s">',$i);
       foreach($row as $column=>$val) {
         $xml.=sprintf("<value name='%s'><![CDATA[%s]]></value>",$column,$val);
       }
       $xml.='</row>';
     }
     $xml.='</result>';
    }
    return $xml;
 }
 function list_tables() {
   $result=mysql_query("SHOW TABLES");
   return sqlresult2xml($result);
 }
 function list_databases() {
   $result=mysql_query("SHOW DATABASES");
   return sqlresult2xml($result);
 }
 ?>